/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { expect } from '@jest/globals';
import * as fse from 'fs-extra';
import { resolve } from 'path';

import { appRoot, initByStageEmptyApp, initExecuteCommand, runHvigor, } from '../../common/common';

describe('test user defined task', () => {
  test.concurrent('test user defined a onlineSignTask', async () => {
    await initByStageEmptyApp(async (projectRoot) => {
      fse.copyFileSync(resolve(appRoot(), 'test/resources/extra/user-defined-task/hvigorfile.ts'),
        resolve(projectRoot, 'entry/hvigorfile.ts'));

      const commands = initExecuteCommand({
        mode: 'module',
        product: 'default',
        tasks: 'assembleHap',
        module: 'entry',
        log: 'i'
      });

      // 第一次执行 expect Finish
      try {
        const result = runHvigor(projectRoot, commands);
        expect(result.stdout.includes('Disabled :entry:default@SignHap...')).toBeTruthy();
      } catch (e: any) {
        expect(e.stderr).toContain('Error: ' +
          'Unable to access jarfile D:\\hapsigntoolv2.jar');
      }
    });
  });
});
